<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>

</body>
<script type="text/javascript">
    // 求1+2!+3!+...+20!的值
    // 1、计算指定数字的阶乘
    var number = 5;
    // 保存number变量的阶乘值
    var sum = 1;
    for (var i = 2; i <= number; i++) {
        sum *= i;
    }
    console.log(sum);
    // 2、1-20阶乘和
    var total = 0;
    for (var j = 1; j <= 20; j++) {

        // 保存number变量的阶乘值
        var sum = 1;
        for (var i = 2; i <= j; i++) {
            sum *= i;
        }
        total += sum;

    }
    console.log(total)
</script>

</html>